//
//  CZStatusRetweetView.swift
//  
//
//  Created by 飞奔的羊 on 16/5/13.
//
//

import UIKit
import SnapKit
class CZStatusRetweetView: UIView {
	///记录底部约束
	var retweetViewBottom: Constraint?
	
	var statusViewModel: CZStatusViewModels? {
		didSet {
		contentLabel.text = statusViewModel?.retweetContent
//		pictureView.picUrls = statusViewModel?.status?.retweeted_status?.pic_urls
			retweetViewBottom?.uninstall()
			//判断转发微博里面配图信息是否存在而且大于0
			if let picUrls = statusViewModel?.status?.retweeted_status?.pic_urls where picUrls.count > 0{
    //显示配图
				pictureView.hidden = false
				//设置配图信息
				pictureView.picUrls = picUrls
				
				//更新约束
				self.snp_updateConstraints(closure: { (make) in
					self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(10).constraint
				})
			} else {
			//隐藏配图视图
			pictureView.hidden = true
				self.snp_updateConstraints(closure: { (make) in
					self.retweetViewBottom = make.bottom.equalTo(contentLabel).offset(10).constraint
				})
			}
			
		}
	
	
	}
	
// MARK: ------懒加载控件------
	//转发微博内容
	private lazy var contentLabel: UILabel = {
		let label = UILabel(textColor: UIColor.grayColor(), fontSIze: 14)
		
	label.numberOfLines = 0
		label.text = "哈哈"
	return label
	}()

	override init(frame: CGRect) {
		super.init(frame: frame)
		setUpUI()
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	private lazy var pictureView: CZStatusPictureView = {
	let view = CZStatusPictureView()
		view.backgroundColor = self.backgroundColor
	return view
	}()
	
	private func setUpUI() {
	self.backgroundColor = UIColor(white: 0.95, alpha: 1)
	 addSubview(contentLabel)
		addSubview(pictureView)
		//设置约束
		pictureView.snp_makeConstraints { (make) in
			make.top.equalTo(contentLabel.snp_bottom).offset(10)
			make.leading.equalTo(contentLabel)
//			make.size.equalTo(CGSize(width: 100, height: 100))
		}
		contentLabel.snp_makeConstraints { (make) in
			make.leading.equalTo(self).offset(10)
			make.top.equalTo(self).offset(10)
			make.trailing.equalTo(self).offset(-10)
		}
		
		//当前视图的约束
		self.snp_makeConstraints { (make) in
			self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(10).constraint
		}
	
	}
}
